﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for MittareCarMoreDetailDB
/// </summary>
namespace CE.CarInsurance
{
    public class MittareCarMoreDetailDB
    {
        public MittareCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(MittareCarMoreDetail mittarecarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemMittare";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", mittarecarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarId", mittarecarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", mittarecarmoredetail.ProviderCompanyId);
            _sPara.Add("@AnnualPremium", mittarecarmoredetail.AnnualPremium);
            _sPara.Add("@TermPremium", mittarecarmoredetail.TermPremium);
            _sPara.Add("@Name", mittarecarmoredetail.Name);
            _sPara.Add("@IdentificationNo", mittarecarmoredetail.IdentificationNo);
            _sPara.Add("@Occupation", mittarecarmoredetail.Occupation);
            _sPara.Add("@ContactNo", mittarecarmoredetail.ContactNo);
            _sPara.Add("@OfficePhoneNo", mittarecarmoredetail.OfficePhoneNo);
            _sPara.Add("@BeneficiaryName", mittarecarmoredetail.BeneficiaryName);

            _sPara.Add("@CarPlate", mittarecarmoredetail.CarPlate);
            _sPara.Add("@CarPlateProvince", mittarecarmoredetail.CarPlateProvince);
            _sPara.Add("@PresentAddress", mittarecarmoredetail.PresentAddress);
            _sPara.Add("@SubDistrict", mittarecarmoredetail.SubDistrict);
            _sPara.Add("@District", mittarecarmoredetail.District);
            _sPara.Add("@Province", mittarecarmoredetail.Province);
            _sPara.Add("@PostalCode", mittarecarmoredetail.PostalCode);
            _sPara.Add("@IsMailingAddressDiff", mittarecarmoredetail.IsMailingAddressDiff);
            _sPara.Add("@MailingAddress", mittarecarmoredetail.MailingAddress);
            _sPara.Add("@MailingSubDistrict", mittarecarmoredetail.MailingSubDistrict);
            _sPara.Add("@MailingDistrict", mittarecarmoredetail.MailingDistrict);
            _sPara.Add("@MailingProvince", mittarecarmoredetail.MailingProvince);
            _sPara.Add("@MailingPostalCode", mittarecarmoredetail.MailingPostalCode);
            _sPara.Add("@EngineNumber", mittarecarmoredetail.EngineNumber);
            _sPara.Add("@ChassisNumber", mittarecarmoredetail.ChassisNumber);
            _sPara.Add("@IsCTPL", mittarecarmoredetail.IsCTPL);
            _sPara.Add("@CTPL", mittarecarmoredetail.CTPL);
            _sPara.Add("@PaymentOption", mittarecarmoredetail.PaymentOption);
            _sPara.Add("@PaymentType", mittarecarmoredetail.PaymentType);
            _sPara.Add("@PaymentBank", mittarecarmoredetail.PaymentBank);

            _sPara.Add("@OrderRefNoId", mittarecarmoredetail.OrderRefNoId);
            _sPara.Add("@OrderRefNo", mittarecarmoredetail.OrderRefNo);
            _sPara.Add("@PaymentStatus", mittarecarmoredetail.PaymentStatus);

            _sPara.Add("@QuoteRefNo", mittarecarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", mittarecarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", mittarecarmoredetail.ViewedDetailId);
            _sPara.Add("@CarResultId", mittarecarmoredetail.CarResultId);
            _sPara.Add("@Ninfo4", mittarecarmoredetail.Ninfo4); // For AgentId
            _sPara.Add("@Ninfo5", mittarecarmoredetail.Ninfo5); // Submission
            _sPara.Add("@Status", mittarecarmoredetail.Status);
            _sPara.Add("@Ninfo1", mittarecarmoredetail.Ninfo1);
            _sPara.Add("@Info1", mittarecarmoredetail.Info1);
            _sPara.Add("@Info2", mittarecarmoredetail.Info2);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public MittareCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            MittareCarMoreDetail _mittarecarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemMittare";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _mittarecarmoredetail = new MittareCarMoreDetail();
                    _mittarecarmoredetail = FillDataRecord(_dt);
                }
            }
            return _mittarecarmoredetail;
        }

        private MittareCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            MittareCarMoreDetail myCarMoreDetail = new MittareCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.AnnualPremium = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremium"].ToString());
            myCarMoreDetail.TermPremium = Convert.ToSingle(myDataTable.Rows[0]["TermPremium"].ToString());
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            if (myDataTable.Rows[0]["IdentificationNo"] != null)
            {
                myCarMoreDetail.IdentificationNo = myDataTable.Rows[0]["IdentificationNo"].ToString();
            }
            myCarMoreDetail.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myCarMoreDetail.ContactNo = myDataTable.Rows[0]["ContactNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            myCarMoreDetail.BeneficiaryName = myDataTable.Rows[0]["BeneficiaryName"].ToString();

            myCarMoreDetail.CarPlate = myDataTable.Rows[0]["CarPlate"].ToString();
            myCarMoreDetail.CarPlateProvince = myDataTable.Rows[0]["CarPlateProvince"].ToString();
            myCarMoreDetail.PresentAddress = myDataTable.Rows[0]["PresentAddress"].ToString();
            myCarMoreDetail.SubDistrict = myDataTable.Rows[0]["SubDistrict"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsMailingAddressDiff = Convert.ToBoolean(myDataTable.Rows[0]["IsMailingAddressDiff"].ToString());
            myCarMoreDetail.MailingAddress = myDataTable.Rows[0]["MailingAddress"].ToString();
            myCarMoreDetail.MailingSubDistrict = myDataTable.Rows[0]["MailingSubDistrict"].ToString();
            myCarMoreDetail.MailingDistrict = myDataTable.Rows[0]["MailingDistrict"].ToString();
            myCarMoreDetail.MailingProvince = myDataTable.Rows[0]["MailingProvince"].ToString();
            myCarMoreDetail.MailingPostalCode = myDataTable.Rows[0]["MailingPostalCode"].ToString();
            myCarMoreDetail.EngineNumber = myDataTable.Rows[0]["EngineNumber"].ToString();
            myCarMoreDetail.ChassisNumber = myDataTable.Rows[0]["ChassisNumber"].ToString();
            myCarMoreDetail.IsCTPL = Convert.ToBoolean(myDataTable.Rows[0]["IsCTPL"].ToString());
            myCarMoreDetail.CTPL = Convert.ToSingle(myDataTable.Rows[0]["CTPL"].ToString());


            myCarMoreDetail.PaymentOption = myDataTable.Rows[0]["PaymentOption"].ToString();
            myCarMoreDetail.PaymentType = myDataTable.Rows[0]["PaymentType"].ToString();
            myCarMoreDetail.PaymentBank = myDataTable.Rows[0]["PaymentBank"].ToString();
            myCarMoreDetail.QuoteRefNo = myDataTable.Rows[0]["QuoteRefNo"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.CarResultId = Convert.ToInt64(myDataTable.Rows[0]["CarResultId"].ToString());
            if (myDataTable.Rows[0]["Ninfo4"] != null)
            {
                myCarMoreDetail.Ninfo4 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo4"].ToString());
            }
            if (myDataTable.Rows[0]["Ninfo5"] != null)
            {
                myCarMoreDetail.Ninfo5 = Convert.ToInt32(myDataTable.Rows[0]["Ninfo5"].ToString());
            }
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            //myCarMoreDetail.Ninfo1 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo1"].ToString());


            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceTHSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

        public Int64 CheckConfirmStatus(Int64 CarId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCheckUserConfirmStatus";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarId", CarId);
            _sPara.Add("@ResultType", ResultType);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

    }
}